﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;

namespace ee_wp_tourmaker
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            applyRightLogo();
            App.MainModel.mainPage = this;
        }

        private void applyRightLogo()
        {
            // Determine the visibility of the dark background. 
            Visibility darkBgTheme = (Visibility)Application.Current.Resources["PhoneDarkThemeVisibility"];
            // Write the theme background value. 
            if (darkBgTheme == Visibility.Visible)
            {
                //Set resources according to dark theme 
                ApplicationLogo.Source = new BitmapImage(new Uri("Icons/logo_white.png", UriKind.RelativeOrAbsolute));
            }
            else
            {
                //Set resources according to light theme
                ApplicationLogo.Source = new BitmapImage(new Uri("Icons/logo_black.png", UriKind.RelativeOrAbsolute));

            }
               
        }

        private void challengeBrowserButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/ChallengeBrowserPivot.xaml", UriKind.Relative));
        }

        private void newChallengeButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/NewChallengePage.xaml", UriKind.Relative));
        }

        private void openMapsButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/MapPage.xaml", UriKind.Relative));
        }

        private void showProfileButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/ProfilePivot.xaml", UriKind.Relative));
        }

        private void aboutButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/AboutPage.xaml", UriKind.Relative));
            App.MainModel.AddAgent();
            App.MainModel.RunDebugAgent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (App.MutexData.Flag.Equals("Challenge"))
            {
                NavigationService.Navigate(new Uri("/Views/FlagChallengePage.xaml", UriKind.Relative));
                App.MutexData.Flag = "";
            }

            if (App.MutexData.Flag.Equals("CheckPoint"))
            {
                NavigationService.Navigate(new Uri("/Views/FlagCheckPointPage.xaml", UriKind.Relative));
                App.MutexData.Flag = "";
            }
            base.OnNavigatedTo(e);
        }
        private void challengeBrowserButton_GotFocus(object sender, RoutedEventArgs e)
        {
            challengeBrowserButton.Background = (Brush)Application.Current.Resources["PhoneAccentBrush"];
        }

        private void newChallengeButton_GotFocus(object sender, RoutedEventArgs e)
        {
            newChallengeButton.Background = (Brush)Application.Current.Resources["PhoneAccentBrush"];
        }

        private void openMapsButton_GotFocus(object sender, RoutedEventArgs e)
        {
            openMapsButton.Background = (Brush)Application.Current.Resources["PhoneAccentBrush"];
        }

        private void showProfileButton_GotFocus(object sender, RoutedEventArgs e)
        {
            showProfileButton.Background = (Brush)Application.Current.Resources["PhoneAccentBrush"];
        }

        private void aboutButton_GotFocus(object sender, RoutedEventArgs e)
        {
            aboutButton.Background = (Brush)Application.Current.Resources["PhoneAccentBrush"];
        }

        public void callSetFlagCheckPoint(object sender, EventArgs args)
        {
           //challengeBrowserButton_Click(null, null);
        }

    }
}